package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Shoppingtrolley;
import org.hxyjs.entity.Shoppingtrolley;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.ShoppingtrolleyService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller
@RequestMapping("/shoppingtrolleyController")
public class ShoppingtrolleyController {
	@Resource
	ShoppingtrolleyService shoppingtrolleyService;
	@RequestMapping("/getAllShoppingtrolley")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Shoppingtrolley> getAllShoppingtrolley() throws Exception {
    	System.out.println("查询全部购物车");
		return shoppingtrolleyService.getAllShoppingtrolleys();
    }

	@RequestMapping("/deleteShoppingtrolleyByStno/{stno}")
	@ResponseBody
    public DTO<Shoppingtrolley> deleteShoppingtrolleyByStno(@PathVariable("stno") String stno) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(stno+"删除购物车");
    	return shoppingtrolleyService.deleteShoppingtrolleyByStno(stno);
    }

	@RequestMapping("/updateShoppingtrolleyByStno")
	@ResponseBody
	public DTO<Shoppingtrolley> updateShoppingtrolleyByStno(@RequestBody Shoppingtrolley shoppingtrolley) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改购物车");
		return shoppingtrolleyService.updateShoppingtrolleyByStno(shoppingtrolley);
	}


	@RequestMapping("/addShoppingtrolley")
	@ResponseBody
	public DTO<Shoppingtrolley> addShoppingtrolley(@RequestBody Shoppingtrolley shoppingtrolley) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加购物车");
		System.out.println(shoppingtrolley);
 		return shoppingtrolleyService.addShoppingtrolley(shoppingtrolley);
	}
	@RequestMapping("/getShoppingtrolleyByPage")
	@ResponseBody
	public DTO<Shoppingtrolley> getShoppingtrolleyByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页管理员");
		return shoppingtrolleyService.getShoppingtrolleyByPage(pageInfo);
	}

}